//
//  MainPageViewController.swift
//  HSSlideMenuView
//
//  Created by haisheng huang on 16/3/10.
//  Copyright © 2016年 haisheng huang. All rights reserved.
//

import UIKit

class MainPageViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.navigationItem.title = "首页"
        self.view.backgroundColor = UIColor.yellowColor()
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "左侧栏", style: UIBarButtonItemStyle.Plain, target: self, action: "openLeftVCAction")
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "右侧栏", style: UIBarButtonItemStyle.Plain, target: self, action: "openRightVCAction")
        
    }
    
    func openLeftVCAction() -> Void {
    
        let tempAppDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
        
        if tempAppDelegate?.leftSlideVc?.closed == true {
            tempAppDelegate?.leftSlideVc?.openLeftView()
        } else {
            tempAppDelegate?.leftSlideVc?.closeLeftView()
        }
        
    }
    
    func openRightVCAction() -> Void {
    
        let tempAppDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
        
        if tempAppDelegate?.leftSlideVc?.closed == true {
            tempAppDelegate?.leftSlideVc?.openRightView()
        } else {
            tempAppDelegate?.leftSlideVc?.closeRightView()
        }
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
        appDelegate?.leftSlideVc?.setPanEnabled(true)
        
    }
    
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        
        let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
        appDelegate?.leftSlideVc?.setPanEnabled(false)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
